package com.share.rules.api.factory;

import com.share.common.core.domain.R;
import com.share.rules.api.RemoteFeeRuleService;
import com.share.rules.api.domain.FeeRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Rule服务降级逻辑处理工厂类
 * @author zxl
 * @date 2025年03月26日 16:45
 */
@Slf4j
@Component
public class RemoteFeeRuleFallbackFactory implements FallbackFactory<RemoteFeeRuleService> {

    @Override
    public RemoteFeeRuleService create(Throwable throwable) {
        log.error("规则服务调用失败：{}", throwable.getMessage());
        return new RemoteFeeRuleService() {
            @Override
            public R<List<FeeRule>> getFeeRuleList(List<Long> feeRuleIdList) {
                return R.fail("获取费用规则列表失败:" + throwable.getMessage());
            }

            @Override
            public R<FeeRule> getFeeRule(Long id) {
                return R.fail("获取费用规则信息失败：" + throwable.getMessage());
            }
        };
    }
}
